//this page was practice code using one of our class tests
//it is not a part of the project code

<?php
class sis extends db{
	function get_all_students_in_course($course_id, $academic_year){
		
		if(!$this->connect()){
			return false;
		}

		$sql = "SELECT student_id, firstname, lastname FROM students, student_course WHERE student_course.student_id =
		$students.student_id AND student_course.course_id = $course_id AND student_course.academic_year = '$academic_year' ";

		if(!$this->query($sql)){
			return false;
		}

		return true;
	}

	function get_course($course_id){

		if(!$this->connect()){
			return false;
		}

		$sql = "SELECT course_id, course_name, course_description FROM courses WHERE course_id = $course_id";

		if(!$this->query($sql)){
			return false;
		}

		return true;

	}
}

$obj = new sis();

if(isset($_REQUEST['course_id'])){
	$id = $_REQUEST['course_id'];
}

if(!$obj->get_courses($id)){
	echo "unable to display course details";
}

$row = $obj->fetch();

echo "<table>";
echo "<tr><td>Course ID</td><td>$row[course_id]</td></tr>";
echo "<tr><td>Course Name</td><td>$row[course_name]</td></tr>";
echo "<tr><td>Course Description</td><td>$row[course_description]</td></tr>";
echo "</table>";

if(isset($_REQUEST['academic_year'])){
	$ac_year = $_REQUEST['academic_year'];
}

if(!$obj->get_all_students_in_course($id, $ac_year)){
	echo "unable to display list of students";
}

if (!$row) {
	$row = $obj->fetch();
}

echo "<table>";
echo "<tr><td>Student ID</td><td>First Name</td><td>Last Name</td></tr>";
while ($row) {
	echo "<tr><td>$row[student_id]</td><td>$row[firstname]</td><td>$row[lastname]</td></tr>";
	$row = $obj->fetch();
}
echo "</table>";

?>